package com.gitee.ed.structure.stream;

import cn.hutool.core.bean.BeanUtil;

import java.util.function.Function;

/**
 * @author hongda.li
 */
public class JoinResult<Left, Right> {

    private final Left left;

    private final Right right;

    public JoinResult(Left left, Right right) {
        this.left = left;
        this.right = right;
    }

    public <Data> Data getLeft(Function<Left, Data> function) {
        return function.apply(left);
    }

    public <Data> Data getRight(Function<Right, Data> function) {
        return function.apply(right);
    }

    public <Merge> Merge merge(Merge merge) {
        BeanUtil.copyProperties(left, merge, true);
        BeanUtil.copyProperties(right, merge, true);
        return merge;
    }

    public <Merge> Merge merge(JoinResultMapping<Left, Right, Merge> mapping) {
        return mapping.merge(left, right);
    }
}
